package com.grandtech.insurance.controller.app;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.grandtech.gmis.common.utils.R;
import com.grandtech.insurance.common.HttpClient;
import com.grandtech.insurance.common.bean.CarriesFeature;
import com.grandtech.insurance.common.db.jdbc.pg.FeatureUtil;
import com.grandtech.insurance.common.db.utils.MapUtil;
import com.grandtech.insurance.common.http.ComHeader;
import com.grandtech.insurance.common.utils.trans.SimpleMap;
import com.grandtech.insurance.common.utils.trans.TileBound;
import com.grandtech.insurance.common.utils.trans.TileBoundReq;
import com.grandtech.insurance.dao.*;
import com.grandtech.insurance.domain.*;
import com.grandtech.insurance.dto.OnlineIns.CarriesFeatureParams;
import com.grandtech.insurance.dto.OnlineIns.Szzb;
import com.grandtech.insurance.dto.OnlineIns.dbkhdkxx;
import com.grandtech.insurance.feign.Nx2ServerBaseService;
import com.grandtech.insurance.feign.NxServerBaseService;
import com.grandtech.insurance.service.DbKhxxService;
import com.grandtech.insurance.service.DbKhyztjService;
import com.grandtech.insurance.service.DksjService;
import com.grandtech.insurance.service.DksjtyService;
import com.grandtech.insurance.service.app.IFeatureService;
import com.grandtech.insurance.service.app.ITileService;
import com.grandtech.insurance.service.app.IVectorTileService;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Geometry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@RequestMapping("/api/v1/feature")
@RestController
public class FeatureController {

    final Logger logger = LogManager.getLogger(FeatureController.class);

    @Autowired
    IFeatureService iFeatureService;

    @Autowired
    IVectorTileService iVectorTileService;

    @Autowired
    OnlineDAO onlineDAO;

    @Autowired
    ITileService tileService;

    @Autowired
    DksjService dksjService;

    @Autowired
    DksjtyService dksjtyService;

    @Autowired
    DbKhdkxxDAO dbKhdkxxDAO;

    @Autowired
    DbKhdkxxptDAO dbKhdkxxptDAO;

    @Autowired
    NxServerBaseService nxServerBaseService;

    @Autowired
    Nx2ServerBaseService nx2ServerBaseService;


    @Autowired
    DbBhjgDAO dbBhjgDAO;

    @Autowired
    DbBhjgDkDAO dbBhjgDkDAO;

    @Autowired
    DbZzjgDAO dbZzjgDAO;

    @Autowired
    DbZhSDAO dbZhSDAO;

    @Autowired
    DbZhjgDAO dbZhjgDAO;

    @Autowired
    YtdkDAO ytdkDAO;


    /**
     * 编辑
     *
     * @param carriesFeatureParams
     * @return
     */
    @Transactional
    @PostMapping("/edit")
    R edit(@RequestBody CarriesFeatureParams carriesFeatureParams) {
        try {
            DbKhdkxx dbkhdkxx = carriesFeatureParams.getdbkhdkxx();
            if (dbkhdkxx.getQhdm() == null || dbkhdkxx.getXmbm() == null ||
                    dbkhdkxx.getNf() == null || dbkhdkxx.getIdcode() == null) {
                return R.error("缺少 qhdm, xmbm, nf, idcode 中一个或多个参数");
            }
            List<CarriesFeature> carriesFeatureList = carriesFeatureParams.getCarriesFeatureList();
            for (CarriesFeature carriesFeature : carriesFeatureList) {
                carriesFeature = ref_carriesFeature(carriesFeature, dbkhdkxx);
                List<CarriesFeature> carriesFeatureList1 = ref_qp(carriesFeature);
                for (CarriesFeature carriesFeature1 : carriesFeatureList1) {
                    SimpleMap<String, Feature> features = carriesFeature1.obtainFeatures();
                    BigDecimal tbmj = new BigDecimal("0");
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份是MM
                    Date modified_time = null;
                    if (features.get("db_khdkxx").getProperty("mj") != null) {
                        tbmj = new BigDecimal(features.get("db_khdkxx").getProperty("mj").toString());
                        modified_time = simpleDateFormat.parse(simpleDateFormat.format(new Date()));
                        dbkhdkxx.setModified_time(new Date());
                    }
                    // carriesFeature1.getCarries().get("db_khdkxx").
                    CarriesFeature r = iVectorTileService.editAndTileFeature(carriesFeature1);

                    /*if (r.get("code").toString().equals("500")) {
                        return R.error("切图失败");
                    }*/
                    Date date = new Date();
                    if (r.getCarries().size() > 0) {
                        //  if (r.get("data") != null) {
/*
                        Dt_cbdk dt_cbdk = JSON.parseObject(JSONObject.toJSONString(r.get("data")), Dt_cbdk.class);

                        yw_cbgcxxb yw_cbgcxxb1 = getgbgcxx(dt_cbdk, yw_cbgcxxb, tbmj);*/
                        //d.setObjectid(dbkhdkx.getObjectid());
                        Map<String, Object> maps = (Map)carriesFeature1.getCarries().get("db_khdkxx");
                        Map<String, Object> maps1 = (Map)maps.get("geometry");
                        String type = maps1.get("type").toString();
                        String coordinates = maps1.get("coordinates").toString();
                        String kj = "{\"type\":\""+type+"\",\"coordinates\":"+coordinates+"}";

                        dbkhdkxx.setMj(tbmj);
                        dbkhdkxx.setModified_time(date);
                        dbkhdkxx.setXyCoordinate(kj);
                        int a = onlineDAO.update(dbkhdkxx);


                        //更新物化视图
                        try{
                            int iii = dbKhdkxxDAO.RefreshSql();
                        }catch (Exception e){

                        }

                        Map map = iFeatureService.pt1(Integer.parseInt(dbkhdkxx.getObjectid()+""));
                        Feature feature = MapUtil.map2Feature(map);
                        String sourceId = "db_khdkxx_pt";
                        feature = iFeatureService.getFeature1(sourceId, map);

                        Map map1 = new HashMap();
                        if (feature != null) {
                            tileService.tileByFeature(sourceId, feature);
                        }

                        //修改客户信息表状态和删除验证统计表和明细表
                        //删除统计表和明细表数据
                        /*DbKhxx dbKhxx1 = new DbKhxx();
                        dbKhxx1.setIdcode(dbkhdkxx.getIdcode());
                        dbKhxx1.setXmbm(dbkhdkxx.getXmbm());
                        DbKhxx dbKhxx2 = dbKhxxService.getDbKhxxByIdcodeAndXmbm(dbKhxx1);
                        if(dbKhxx2!=null){
                            DbKhxx dbKhxx3 = new DbKhxx();
                            dbKhxx3.setId(dbKhxx2.getId());
                            dbKhxx3.setIdcode(dbKhxx2.getIdcode());
                            dbKhxx3.setXmbm(dbKhxx2.getXmbm());
                            dbKhxx3.setYzstate(0);
                            dbKhxx3.setF(0);
                            int updatekhxx = dbKhxxService.updateByPrimaryKeySelective(dbKhxx3);
                            int deletetj = dbKhyztjService.deleteDbKhyztj(dbKhxx3);
                            int deletemx = dbKhyztjService.deleteDbKhyzmx(dbKhxx3);
                        }*/

                    } else {
                        return R.error("切图失败");
                    }
                }
            }
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.toString());
        }
    }

    @PostMapping("/query")
    public R queryFeature(@RequestBody CarriesFeature carriesFeature) {
        try {
            if (carriesFeature == null) {
                return R.error("未能找到要保存的要素！");
            }
            SimpleMap<String, Feature> features = carriesFeature.obtainFeatures();
            Feature feature = null;
            CarriesFeature result = CarriesFeature.create();
            for (String tableName : features.keySet()) {
                feature = features.get(tableName);
                Feature resItem = iFeatureService.getFeature(tableName, feature);
                result.addFeature(tableName, resItem);
            }
            return R.ok().put("data", result);
        } catch (Exception e) {
            logger.info(e.getMessage());
            return R.error("服务异常:" + e.toString());
        }
    }

    @GetMapping("/getNextValue")
    public R getNextValue() {
        try {

            return R.data(ytdkDAO.getNextValueDk());
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("服务异常:" + e.toString());
        }
    }



    @Transactional
    @PostMapping("/add")
    R add(@RequestBody CarriesFeatureParamsqp carriesFeatureParams){
        try {
            String bm = "";
            List<CarriesFeature> carriesFeatureList = carriesFeatureParams.getCarriesFeatureList();
            for (CarriesFeature carriesFeature : carriesFeatureList){
                List<CarriesFeature> carriesFeatureList1 = ref_qp1(carriesFeature);
                for (CarriesFeature carriesFeature1 : carriesFeatureList1){
                    //切图
                    if (carriesFeature1 == null) return R.error("未能找到要保存的要素！");

                    String s = JSONArray.toJSON(carriesFeature1).toString();
                    carriesFeature1 = (CarriesFeature) JSON.parseObject(s,CarriesFeature.class);


                    CarriesFeature res = iVectorTileService.saveAndTileFeature(carriesFeature1);
                    Map<String, Object> properties = res.obtainFeatureDefaultProperties();
                    R r = R.data(properties);
                    if (r.get("code").toString().equals("500")) {
                        return R.error("切图失败");
                    }
                }
            }
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }


    @Transactional
    @PostMapping("/addAndDelete")
    R addAndDelete(@RequestBody AddAndDeleteModel model){
        try {
            String bm = "";
            if(model.getIds()!=null&&model.getIds().size()>0){
                ytdkDAO.copyData(model.getIds());
                ytdkDAO.deletes(model.getIds());
            }

            R r=add(model.getAddFeature());
            return r;
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }



    @Transactional
    @PostMapping("/batchAdd")
    public R batchAdd(@RequestBody List<Ytdk> ytdks){
        try {
           ytdkDAO.batchAddOrUpdate(ytdks);
            for (int i = 0; i < ytdks.size(); i++) {
               tileService.tileByFeature("ytdk0305",Feature.fromGeometry(Geometry.fromJson(ytdks.get(i).getGeom())));
            }

            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }


    @Transactional
    @PostMapping("/delete")
    R delete(@RequestBody CarriesFeatureParamsqp carriesFeatureParams){
        try {
            List<CarriesFeature> carriesFeatureList = carriesFeatureParams.getCarriesFeatureList();
            for (CarriesFeature carriesFeature : carriesFeatureList){
                carriesFeature = ref_carriesFeature_delete1(carriesFeature);
                List<CarriesFeature> carriesFeatureList1 = ref_qp1(carriesFeature);
                for (CarriesFeature carriesFeature1 : carriesFeatureList1){

                    if (carriesFeature1 == null) return R.error("未能找到要保存的要素！");
                    CarriesFeature res = iVectorTileService.delAndTileFeature(carriesFeature1);
                    Map<String, Object> properties = res.obtainFeatureDefaultProperties();
                    R r = R.data(properties);
                    if (r.get("code").toString().equals("500")) {
                        return R.error("切图失败");
                    }

                    if (r.get("data") != null){
                        DbKhdkxx dbkhdkx = JSON.parseObject(JSONObject.toJSONString(r.get("data")), DbKhdkxx.class);

                        int i = dksjService.deleteByPrimaryKey(dbkhdkx.getObjectid());
                    }

                }
            }
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    public CarriesFeature ref_carriesFeature_add1(CarriesFeature carriesFeature){
        SimpleMap<String, Object> carriesMap = carriesFeature.getCarries();
        List<Map> mapList = (List<Map>) JSONArray.parseArray(JSONObject.toJSONString(carriesMap.get("db_khdkxx")), Map.class);
        List<Map> mapListRes = new ArrayList<>();
        for (Map dbkhdkxxMap : mapList){
            ObjectMapper objectMapper = new ObjectMapper();
            //String kj1 = dbkhdkxxMap.get("geometry").toString();
            Map<String, Object> maps = (Map)dbkhdkxxMap.get("geometry");
            String type = maps.get("type").toString();
            String coordinates = maps.get("coordinates").toString();
            String kj = "{\"type\":\""+type+"\",\"coordinates\":"+coordinates+"}";
            //中心点
            String center = dksjService.getCenter(kj);
            //跨服务获取村级区划
            Map qqq = new HashMap<>();
            qqq.put("geo",center);
//            String cun = nxServerBaseService.getCyList(qqq);
            Cy cy = new Cy();
//            if(cun!=null && !"".equals(cun)){
//                cy = JSON.parseObject(cun, Cy.class);
//            }

            //清除modified_time，防止报错
            Map<String, Object> maps1 = (Map)dbkhdkxxMap.get("properties");
            maps1.remove("modified_time");

            DbKhdkxx dbkhdkxx_properties = JSON.parseObject(maps1.toString(), DbKhdkxx.class);
            //dbkhdkxx_properties.setId(UUIDTool.get32UUID());  //更新单个dt_cbdk字段属性
            //dbkhdkxx_properties.setId("666");
            dbkhdkxx_properties.setCreateTime(new Date());
            dbkhdkxx_properties.setQhdm(cy.getQhdm());
            dbkhdkxx_properties.setQhmc(cy.getQhmc());


            dbkhdkxx_properties.setXyCoordinate(kj);
            //获取地块编码

            dbkhdkxx_properties.setDkbm("***");
            dbkhdkxxMap.put("properties", dbkhdkxx_properties);
            mapListRes.add(dbkhdkxxMap);
        }
        SimpleMap<String, Object> carriesMapres = new SimpleMap<>();
        carriesMapres.put("db_khdkxx", mapListRes);
        carriesFeature.setCarries(carriesMapres);
        return carriesFeature;
    }


    public CarriesFeature ref_carriesFeature_delete1(CarriesFeature carriesFeature) {
        SimpleMap<String, Object> carriesMap = carriesFeature.getCarries();
        List<Map> mapList = (List<Map>) JSONArray.parseArray(JSONObject.toJSONString(carriesMap.get("db_khdkxx")), Map.class);
        List<Map> mapListRes = new ArrayList<>();
        for (Map dbkhdkxxMap : mapList) {
            ObjectMapper objectMapper = new ObjectMapper();

            Map<String, Object> maps = (Map)dbkhdkxxMap.get("geometry");
            String type = maps.get("type").toString();
            String coordinates = maps.get("coordinates").toString();
            String kj = "{\"type\":\""+type+"\",\"coordinates\":["+coordinates+"]}";

            DbKhdkxx dbkhdkxx_properties = JSON.parseObject(dbkhdkxxMap.get("properties").toString(), DbKhdkxx.class);
            //dbkhdkxx_properties.setId(UUIDTool.get32UUID());  //更新单个dt_cbdk字段属性
            if(dbkhdkxx_properties.getQhdm().length()>=2){
                dbkhdkxx_properties.setProvincecode(dbkhdkxx_properties.getQhdm().substring(0, 2));
            }
            if(dbkhdkxx_properties.getQhdm().length()>=4) {
                dbkhdkxx_properties.setCitycode(dbkhdkxx_properties.getQhdm().substring(0, 4));
            }
            if(dbkhdkxx_properties.getQhdm().length()>=6) {
                dbkhdkxx_properties.setCountycode(dbkhdkxx_properties.getQhdm().substring(0, 6));
            }
            if(dbkhdkxx_properties.getQhdm().length()>=9) {
                dbkhdkxx_properties.setTowncode(dbkhdkxx_properties.getQhdm().substring(0, 9));
            }
            dbkhdkxx_properties.setXyCoordinate(kj);
            //获取地块编码
            /*DbKhdkxx params=new DbKhdkxx();
            params.setQhdm(dbkhdkxx_properties.getQhdm());
            params.setZytype(dbkhdkxx_properties.getZytype());
            String dkbm = dksjService.getListDkbm(params);
            if(dkbm!=null){
                dkbm = Long.valueOf(dkbm)+1+"";
            }else{
                dkbm = dbkhdkxx_properties.getQhdm()+dbkhdkxx_properties.getZytype()+"0001";
            }
            dbkhdkxx_properties.setDkbm(dkbm);*/
            dbkhdkxxMap.put("properties", dbkhdkxx_properties);
            mapListRes.add(dbkhdkxxMap);
        }
        SimpleMap<String, Object> carriesMapres = new SimpleMap<>();
        carriesMapres.put("db_khdkxx", mapListRes);
        carriesFeature.setCarries(carriesMapres);
        return carriesFeature;
    }

    public List<CarriesFeature> ref_qp1(CarriesFeature carriesFeature) {
        List<CarriesFeature> carriesFeatureListres = new ArrayList<>();
        SimpleMap<String, Object> carriesMap = carriesFeature.getCarries();
        List<Map> dt_cbdkMapList = (List<Map>) JSONArray.parseArray(JSONObject.toJSONString(carriesMap.get("ytdk0305")), Map.class);
        for (Map dt_cbdkMap : dt_cbdkMapList) {
            CarriesFeature carriesFeature2 = new CarriesFeature();
            SimpleMap<String, Object> carriesMap2 = new SimpleMap<>();
            carriesMap2.put("ytdk0305", dt_cbdkMap);
            carriesFeature2.setCarries(carriesMap2);
            carriesFeatureListres.add(carriesFeature2);
        }
        return carriesFeatureListres;
    }


    public CarriesFeature ref_carriesFeature(CarriesFeature carriesFeature, DbKhdkxx dbkhdkxx) throws ParseException {
        SimpleMap<String, Object> carriesMap = carriesFeature.getCarries();
        List<Map> mapList = (List<Map>) JSONArray.parseArray(JSONObject.toJSONString(carriesMap.get("db_khdkxx")), Map.class);
        List<Map> mapListRes = new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份是MM
        String date = simpleDateFormat.format(new Date());
        for (Map dbkhdkxxMap : mapList) {
            ObjectMapper objectMapper = new ObjectMapper();
            DbKhdkxx dbkhdkxx_properties = JSON.parseObject(dbkhdkxxMap.get("properties").toString(), DbKhdkxx.class);
            dbkhdkxx_properties.setObjectid(dbkhdkxx.getObjectid());  //更新单个dt_cbdk字段属性
            dbkhdkxx_properties.setProvincecode(dbkhdkxx.getQhdm().substring(0, 2));
            dbkhdkxx_properties.setCitycode(dbkhdkxx.getQhdm().substring(0, 4));
            dbkhdkxx_properties.setCountycode(dbkhdkxx.getQhdm().substring(0, 6));
            dbkhdkxx_properties.setDkbm(dbkhdkxx.getDkbm());
            dbkhdkxx_properties.setDkmc(dbkhdkxx_properties.getDkbm().substring(dbkhdkxx_properties.getDkbm().length() - 4, dbkhdkxx_properties.getDkbm().length()));
            dbkhdkxx_properties.setXmbm(dbkhdkxx.getXmbm());
            dbkhdkxxMap.put("properties", dbkhdkxx_properties);
            mapListRes.add(dbkhdkxxMap);
        }
        SimpleMap<String, Object> carriesMapres = new SimpleMap<>();
        carriesMapres.put("dbkhdkxx", mapListRes);
        carriesFeature.setCarries(carriesMapres);
        return carriesFeature;
    }

    public List<CarriesFeature> ref_qp(CarriesFeature carriesFeature) {
        List<CarriesFeature> carriesFeatureListres = new ArrayList<>();
        SimpleMap<String, Object> carriesMap = carriesFeature.getCarries();
        List<Map> dt_cbdkMapList = (List<Map>) JSONArray.parseArray(JSONObject.toJSONString(carriesMap.get("dbkhdkxx")), Map.class);
        for (Map dt_cbdkMap : dt_cbdkMapList) {
            CarriesFeature carriesFeature2 = new CarriesFeature();
            SimpleMap<String, Object> carriesMap2 = new SimpleMap<>();
            carriesMap2.put("db_khdkxx", dt_cbdkMap);
            carriesFeature2.setCarries(carriesMap2);

            carriesFeatureListres.add(carriesFeature2);
        }
        return carriesFeatureListres;
    }

    /**
     * 保存涂鸦数据
     *
     * @param po
     */
    @Transactional
    @PostMapping("/saveGraffiti")
     R saveGraffiti(@RequestBody DbKhtydkxx po) {
        String bm = "";
        try {

            //id为空是新增
            if(po.getObjectid()==null){
                //获取村级区划
                String center = dksjService.getCenter(po.getShape().toString());
                //跨服务获取村级区划
                Map qqq = new HashMap<>();
                qqq.put("geo",center);
//                String cun = nxServerBaseService.getCyList(qqq);
                Cy cy = new Cy();
//                if(cun!=null && !"".equals(cun)){
//                    cy = JSON.parseObject(cun, Cy.class);
//                }
                po.setQhdm(cy.getQhdm());
                po.setQhmc(cy.getQhmc());
                //获取地块编码
                DbKhtydkxx params=new DbKhtydkxx();
                params.setQhdm(po.getQhdm());
                params.setZytype(po.getZytype());
                params.setNf(po.getNf());
                String nnff = "";
                if(po.getNf()!=null && po.getNf().length()==4){
                    nnff = po.getNf().substring(2);
                }
                String dkbm = dksjService.getListDkbm1(params);
                if(dkbm!=null){
                    BigDecimal dddd = new BigDecimal(dkbm);
                    dkbm = dddd.add(new BigDecimal(1))+"";
                }else{
                    dkbm = po.getQhdm()+po.getZytype()+nnff+"0001";
                }
                po.setDkbm(dkbm);
                bm = dkbm;
            }
            if(po.getQhdm().length()>=2){
                po.setProvincecode(po.getQhdm().substring(0, 2));
            }
            if(po.getQhdm().length()>=4){
                po.setCitycode(po.getQhdm().substring(0, 4));
            }
            if(po.getQhdm().length()>=6){
                po.setCountycode(po.getQhdm().substring(0, 6));
            }
            if(po.getQhdm().length()>=9){
                po.setTowncode(po.getQhdm().substring(0, 9));
            }
            po.setXyCoordinate(po.getShape().toString());

            Map map = JSON.parseObject(JSON.toJSONString(po), Map.class);
            Feature feature = MapUtil.map2Feature(map);
            String sourceId = "db_khtydkxx";
            feature = FeatureUtil.featureInsertBeforeTile(feature);
            feature = iFeatureService.insertOrUpdateF(sourceId, feature);

            String objectid = feature.properties().get("objectid").toString();

            if (feature != null) {
                tileService.tileByFeature(sourceId, feature);
            }

            //更新涂鸦数据
            DbKhtydkxx t = new DbKhtydkxx();
            t.setObjectid(Long.valueOf(objectid));
            t.setXyCoordinate(po.getShape()+"");
            Date date = new Date();
            t.setCreateTime(date);
            t.setModifiedTime(date);
            int upd = dksjtyService.updateByPrimaryKeySelective(t);


            //更新物化视图
            try{
                int iii = dbKhdkxxDAO.RefreshSql1();
            }catch (Exception e){

            }

            Map map1 = iFeatureService.pt2(Integer.parseInt(objectid));
            Feature feature1 = MapUtil.map2Feature(map1);
            String sourceId1 = "db_khtydkxx_pt";
            feature1 = iFeatureService.getFeature1(sourceId1, map1);

            if (feature1 != null) {
                tileService.tileByFeature(sourceId1, feature1);
            }

            return R.ok().put("dkbm",bm);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("saveGraffiti error.msg:{}", e.getMessage());
            return R.error();
        }
    }


    //地块删除切片
    @Transactional
    @GetMapping("/delete1")
     R delete1(@RequestParam("objectid") Integer objectid) {
        logger.info("delete start.objectid:{}", objectid);
        try {

            Ytdk ytdk = new Ytdk();
            ytdk.setObjectid(objectid.longValue());

            Map map = iFeatureService.getGraffitiByObjectid1(objectid);
            Feature feature = MapUtil.map2Feature(map);
            String sourceId = "ytdk0305";
            feature = FeatureUtil.featureDelBeforeTile(feature);
            ytdkDAO.deleteByPrimaryKey(objectid);
            if (feature != null) {
                tileService.tileByFeature(sourceId, feature);
            }

            return R.ok();
        } catch (Exception e) {
            logger.error("deleteerror.msg:{}", e);
            return R.error();
        }
    }


    @Transactional
    @PostMapping("/deletes")
    R deletes(@RequestBody List<Long> ids) {
        try {
            if(ids.size()>0){
             BoundBox boundBox=ytdkDAO.getBoundBox(ids);
             ytdkDAO.copyData(ids);
             ytdkDAO.deletes(ids);
            String sourceId = "ytdk0305";
                if (boundBox != null) {
                    BoundingBox boundingBox=BoundingBox.fromLngLats(boundBox.getxMin(), boundBox.getyMin(), boundBox.getxMax(), boundBox.getyMax());
                    tileService.tileByBound(sourceId, boundingBox);
                }
            }
            return R.ok();
        } catch (Exception e) {
            logger.error("delete error.msg:{}", e);
            return R.error();
        }
    }
}














